/**
 * 
 */
package tech.abing.spider.task.pipeline.amac;

import java.util.List;

import org.apache.log4j.Logger;

import tech.abing.spider.component.Pipeline;
import tech.abing.spider.model.Proccessable;
import tech.abing.spider.task.model.amac.FundInfoEntity;
import tech.abing.spider.task.model.amac.FundStatEntity;
import tech.abing.spider.task.model.amac.PrivateDirectInvestMentFund;
import tech.abing.spider.task.model.amac.PrivateDirectInvestMentFundStatEntity;
import tech.abing.spider.util.ProccessableUtil;
import tech.abing.spider.util.SqlUtil;

/**
 * 类说明
 * @author HUNING
 * @since 2018-1-4
 * 
 */
public class PrivateDirectInvestmentFundPipeline implements Pipeline{
	/**
 * 
 */
private static final long serialVersionUID = -5037419114999788248L;
private static Logger logger = Logger.getLogger(PrivateDirectInvestmentFundPipeline.class);
private static SqlUtil sqlUtil = null;

public PrivateDirectInvestmentFundPipeline(){
	if(sqlUtil == null){
		sqlUtil = SqlUtil.getInstance();
		logger.info("数据库连接创建成功！");
	}
}

@Override
public void proccessData(List<Proccessable> objectContainer) {
	
	// 统计数据新增
	if(!objectContainer.isEmpty()){
		for (Proccessable proccessable : objectContainer) {
			if(proccessable.getClass().getName().equals(PrivateDirectInvestMentFundStatEntity.class.getName())){
				sqlUtil.insert(sqlUtil.getConn(), (PrivateDirectInvestMentFundStatEntity)proccessable);
			}
			if(proccessable.getClass().getName().equals(PrivateDirectInvestMentFund.class.getName())){
				sqlUtil.insert(sqlUtil.getConn(), (PrivateDirectInvestMentFund)proccessable);
			}
		}
	}
	
//	if(ProccessableUtil.instanceOfClass(objectContainer, PrivateDirectInvestMentFund.class)){//判断集合类型
//		List<PrivateDirectInvestMentFund> list = ProccessableUtil.convert(objectContainer, PrivateDirectInvestMentFund.class);
//		
//		sqlUtil.batchInsert(sqlUtil.getConn(), PrivateDirectInvestMentFund.class, list);
//	}
	
}

@Override
public void destory() {
	if(sqlUtil != null){
		sqlUtil.closeConn();
		sqlUtil = null;
		logger.info("数据库连接关闭成功！");
	}
}

}
